//
//  FFRecvPayPaySuccessVC.m
//  LLWallet
//
//  Created by tt on 2020/12/23.
//

#import "FFRecvPayPaySuccessVC.h"

@interface FFRecvPayPaySuccessVC ()

@property(nonatomic,strong) UIImageView *paysuccessIcon;
@property(nonatomic,strong) UILabel *paysuccessLbl;


@property(nonatomic,strong) UILabel *amountLbl;

@property(nonatomic,strong) UILabel *payeeLbl;
@property(nonatomic,strong) UIImageView *userAvatarImgView;
@property(nonatomic,strong) UILabel *nameLbl;

@property(nonatomic,strong) UIButton *completeBtn;

@end

@implementation FFRecvPayPaySuccessVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationBar.hidden = YES;
    
    [self.view addSubview:self.paysuccessIcon];
    [self.view addSubview:self.paysuccessLbl];
    [self.view addSubview:self.amountLbl];
    [self.view addSubview:self.payeeLbl];
    [self.view addSubview:self.userAvatarImgView];
    [self.view addSubview:self.nameLbl];
    [self.view addSubview:self.completeBtn];
    
    WKChannelInfo*channelInfo = [[WKSDK shared].channelManager getChannelInfo:[WKChannel personWithChannelID:self.uid]];
    if(channelInfo) {
        self.nameLbl.text = channelInfo.displayName;
        [self.nameLbl sizeToFit];
    }
    [self.userAvatarImgView lim_setImageWithURL:[NSURL URLWithString:[WKAvatarUtil getAvatar:self.uid]] placeholderImage:[WKApp shared].config.defaultAvatar];
    
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString: [NSString stringWithFormat:@"¥%@",[WKMoneyUtil penny2YuanFormat:@(self.amount)]]];
    [str addAttribute:NSFontAttributeName value:[[WKApp shared].config appFontOfSizeSemibold:20.0f] range:NSMakeRange(0, 1)];
    
    self.amountLbl.attributedText = str;
    [self.amountLbl sizeToFit];
    
    
}

- (NSString *)langTitle {
    return LLang(@"支付成功");
}

- (void)viewConfigChange:(WKViewConfigChangeType)type {
    if(type ==  WKViewConfigChangeTypeStyle) {
        if([WKApp shared].config.style == WKSystemStyleDark) {
            self.view.backgroundColor = [UIColor blackColor];
        }else{
            self.view.backgroundColor = [UIColor whiteColor];
        }
    }
}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    
    [self layoutViews];
}

-(void) layoutViews {
    self.paysuccessIcon.lim_centerX_parent = self.view;
    self.paysuccessIcon.lim_top = self.navigationBar.lim_bottom + 10.0f;
    
    self.paysuccessLbl.lim_centerX_parent = self.view;
    self.paysuccessLbl.lim_top = self.paysuccessIcon.lim_bottom + 10.0f;
    
    
    self.amountLbl.lim_centerX_parent = self.view;
    self.amountLbl.lim_top = self.paysuccessLbl.lim_bottom + 60.0f;
    
    self.payeeLbl.lim_top = self.amountLbl.lim_bottom + 100.0f;
    self.payeeLbl.lim_centerX_parent = self.view;
    
    self.userAvatarImgView.lim_centerX_parent = self.view;
    self.userAvatarImgView.lim_top = self.payeeLbl.lim_bottom + 30.0f;
    
    self.nameLbl.lim_centerX_parent = self.view;
    self.nameLbl.lim_top = self.userAvatarImgView.lim_bottom + 10.0f;
    

    CGFloat bottomSafe = 0.0f;
    if (@available(iOS 11.0, *)) {
         bottomSafe = [UIApplication sharedApplication].keyWindow.safeAreaInsets.bottom;
    }
    self.completeBtn.lim_top = self.view.lim_height - self.completeBtn.lim_height - bottomSafe - 80.0f;
    self.completeBtn.lim_centerX_parent = self.view;
}

- (UIImageView *)paysuccessIcon {
    if(!_paysuccessIcon) {
        _paysuccessIcon = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 32.0f, 32.0f)];
        _paysuccessIcon.image = [self imageName:@"paysuccess"];
    }
    return _paysuccessIcon;
}

- (UILabel *)paysuccessLbl {
    if(!_paysuccessLbl) {
        _paysuccessLbl = [[UILabel alloc] init];
        _paysuccessLbl.textColor = [WKApp shared].config.themeColor;
        _paysuccessLbl.text  =LLang(@"支付成功");
        [_paysuccessLbl sizeToFit];
    }
    return _paysuccessLbl;
}


- (UILabel *)amountLbl {
    if(!_amountLbl) {
        _amountLbl = [[UILabel alloc] init];
        _amountLbl.font = [[WKApp shared].config appFontOfSizeSemibold:50.0f];
    }
    return _amountLbl;
}

- (UILabel *)payeeLbl {
    if(!_payeeLbl) {
        _payeeLbl = [[UILabel alloc] init];
        _payeeLbl.font = [[WKApp shared].config appFontOfSize:12.0f];
        _payeeLbl.text = LLang(@"收款方");
        _payeeLbl.textColor = [WKApp shared].config.tipColor;
        [_payeeLbl sizeToFit];
    }
    return _payeeLbl;
}

- (UIImageView *)userAvatarImgView {
    if(!_userAvatarImgView) {
        _userAvatarImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 64.0f, 64.0f)];
        _userAvatarImgView.layer.masksToBounds = YES;
        _userAvatarImgView.layer.cornerRadius = _userAvatarImgView.lim_height/2.0f;
    }
    return _userAvatarImgView;
}

- (UILabel *)nameLbl {
    if(!_nameLbl) {
        _nameLbl = [[UILabel alloc] init];
        _nameLbl.font = [[WKApp shared].config appFontOfSize:16.0f];
    }
    return _nameLbl;
}

- (UIButton *)completeBtn {
    if(!_completeBtn) {
        _completeBtn = [[UIButton alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 180.0f, 40.0f)];
        [_completeBtn setTitle:LLang(@"完成") forState:UIControlStateNormal];
        [_completeBtn setTitleColor:[WKApp shared].config.themeColor forState:UIControlStateNormal];
        _completeBtn.backgroundColor = [UIColor colorWithRed:242.0f/255.0f green:242.0f/255.0f blue:242.0f/255.0f alpha:1.0f];
        _completeBtn.layer.masksToBounds = YES;
        _completeBtn.layer.cornerRadius = 4.0f;
        [_completeBtn addTarget:self action:@selector(completePressed) forControlEvents:UIControlEventTouchUpInside];
    }
    return _completeBtn;
}

-(void) completePressed {
    [[WKNavigationManager shared] popToRootViewControllerAnimated:YES];
}


-(UIImage*) imageName:(NSString*)name {
    return [[WKApp shared] loadImage:name moduleID:@"LLWallet"];
}

@end
